﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.MiniQuest {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Engine.Helpers.*;
    import Classes.*;
    import flash.filters.*;
    import Display.*;
    import flash.text.*;

    public class MiniQuest {

        protected var m_questIconURL:String;
        protected var m_questHudIcon:DisplayObjectContainer = null;
        protected var m_questHudIconAnim:AutoAnimatedBitmap = null;
        protected var m_numFrames:int;
        protected var m_iconWidth:int;
        protected var m_iconHeight:int;
        protected var m_iconFps:int;
        protected var m_assetsLoaded:Boolean = false;
        protected var m_questActive:Boolean = false;
        protected var m_questName:String = "";
        protected var m_recurrenceTime:Number = 45;

        public function MiniQuest(_arg1:String):void{
            var _local2:XML;
            var _local3:XML;
            super();
            this.m_questName = _arg1;
            if (!this.m_questHudIconAnim){
                _local2 = Global.gameSettings.getIconXMLByName(this.m_questName);
                if (_local2){
                    _local3 = _local2.image[0];
                    this.m_numFrames = ((_local3.@fps) || (1));
                    this.m_iconWidth = _local3.@frameWidth;
                    this.m_iconHeight = _local3.@frameHeight;
                    this.m_iconFps = _local3.@fps;
                    this.m_questIconURL = _local3.asset.@url;
                    LoadingManager.load(Global.getAssetURL(this.m_questIconURL), this.onIconLoaded);
                };
            };
        }
        public function get recurrenceTime():int{
            return (this.m_recurrenceTime);
        }
        public function toggleMiniQuest(_arg1:Boolean):void{
            if (_arg1){
                this.initQuest();
            } else {
                this.endQuest();
            };
        }
        protected function onIconLoaded(_arg1:Event):void{
            var _local4:Bitmap;
            var _local2:Loader = (_arg1.target.loader as Loader);
            if ((_local2.content is Bitmap)){
                _local4 = (_local2.content as Bitmap);
                this.m_questHudIconAnim = new AutoAnimatedBitmap(_local4.bitmapData, this.m_numFrames, (this.m_iconWidth) ? this.m_iconWidth : _local4.width, (this.m_iconHeight) ? this.m_iconHeight : _local4.height, (this.m_iconFps) ? this.m_iconFps : 1);
                this.m_assetsLoaded = true;
            };
            this.m_questHudIcon = new Sprite();
            this.m_questHudIcon.addChild(this.m_questHudIconAnim);
            var _local3:String = this.miniQuestLabel;
            if (_local3){
                this.m_questHudIcon.addChild(this.makeLabel(_local3, (this.m_iconWidth) ? this.m_iconWidth : _local4.width));
            };
        }
        protected function initQuest():void{
            var _local1:String;
            var _local2:Boolean;
            if (((this.m_assetsLoaded) && (!(this.m_questActive)))){
                _local1 = ZLoc.t("Dialogs", ("Mini_" + this.m_questName));
                _local2 = Global.hud.showMiniQuestSprite(this.m_questName, _local1, this.m_questHudIcon, this.onIconClicked);
                if (!_local2){
                    return;
                };
                Global.hud.showGoalsProgressOverlayOnQuestIcon(this.m_questName, "click");
                this.m_questActive = true;
            };
        }
        protected function endQuest():void{
            Global.hud.hideMiniQuestSprite(this.m_questName, this.onIconClicked);
            if (this.m_questHudIconAnim){
                this.m_questHudIconAnim.cleanUp();
                this.m_questHudIconAnim = null;
            };
            this.m_questHudIcon = null;
        }
        protected function onIconClicked(_arg1:MouseEvent):void{
            Global.hud.hideMiniQuestSprite(this.m_questName, this.onIconClicked);
            this.m_questActive = false;
        }
        public function get miniQuestName():String{
            return (this.m_questName);
        }
        protected function get miniQuestLabel():String{
            return (null);
        }
        protected function get miniQuestLabelOffset():Vector2{
            return (null);
        }
        public function deactivate():void{
            this.endQuest();
            this.m_questActive = false;
        }
        protected function makeLabel(_arg1:String, _arg2:Number):DisplayObject{
            var _local3:TextFormat = new TextFormat();
            _local3.color = EmbeddedArt.yellowTextColor;
            _local3.align = TextFormatAlign.CENTER;
            var _local4:Number = TextFieldUtil.getLocaleFontSize(12, 10, null);
            _local3.size = _local4;
            var _local5:TextField = new TextField();
            if (Global.localizer.langCode != "en"){
                _local3.font = EmbeddedArt.DEFAULT_FONT_NAME;
                _local5.width = (_arg2 + 10);
            } else {
                _local3.font = EmbeddedArt.TITLE_FONT;
                _local5.width = _arg2;
            };
            _local5.multiline = true;
            _local5.wordWrap = true;
            _local5.selectable = false;
            _local5.autoSize = TextFieldAutoSize.CENTER;
            _local5.text = _arg1;
            _local5.embedFonts = true;
            _local5.antiAliasType = AntiAliasType.ADVANCED;
            _local5.gridFitType = GridFitType.PIXEL;
            _local5.setTextFormat(_local3);
            _local5.filters = [new GlowFilter(EmbeddedArt.orangeTextColor, 1, 3, 3, 5, BitmapFilterQuality.LOW), new DropShadowFilter(1, 45, EmbeddedArt.blackTextColor, 0.6, 3, 3, 6)];
            var _local6:Vector2 = this.miniQuestLabelOffset;
            if (_local6){
                _local5.x = _local6.x;
                _local5.y = _local6.y;
            };
            return (_local5);
        }

    }
}//package Classes.MiniQuest 
